home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / gui / gtlayout.lha / Source / LT_InitExit.c < prev    next >
C/C++ Source or Header  |  1999-01-03  |  7KB  |  348 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1999 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <exec/memory.h>
  17. #include <libraries/locale.h>
  18.  
  19. #include <clib/alib_protos.h>    /* For NewList */
  20.  
  21. #include <clib/locale_protos.h>
  22. #include <pragmas/locale_pragmas.h>
  23.  
  24. /*****************************************************************************/
  25.  
  26. #include "Assert.h"
  27.  
  28. /*****************************************************************************/
  29.  
  30. STATIC struct LocaleBase *    LocaleBase;
  31. STATIC struct Locale *        DefaultLocale;
  32.  
  33. /*****************************************************************************/
  34.  
  35.  
  36. /****** gtlayout.library/LT_Init ******************************************
  37. *
  38. *   NAME
  39. *    LT_Init -- Initialize user interface code.
  40. *
  41. *   SYNOPSIS
  42. *    LT_Init();
  43. *
  44. *    VOID LT_Init(VOID);
  45. *
  46. *   FUNCTION
  47. *    You need to initialize the user interface code only once,
  48. *    so it can set up its internals, open libraries, etc.
  49. *    The code has to be initialized before any user interface
  50. *    creation can take place.
  51. *
  52. *   NOTES
  53. *    This function is not present in the shared library, only
  54. *    in the link library. You need not and cannot invoke it in
  55. *    the shared library.
  56. *
  57. *   SEE ALSO
  58. *    gtlayout.library/LT_Exit
  59. *
  60. ******************************************************************************
  61. *
  62. */
  63.  
  64. /*****************************************************************************/
  65.  
  66. struct LibraryInitEntry
  67. {
  68.     BOOL                MustOpen;
  69.     STRPTR                Name;
  70.     struct Library **    Library;
  71. };
  72.  
  73. struct ClassInitEntry
  74. {
  75.     STRPTR                ClassName;
  76.     LONG                InstanceSize;
  77.     HOOKFUNC            Dispatcher;
  78.     Class **            ClassPtr;
  79. };
  80.  
  81. /*****************************************************************************/
  82.  
  83. BOOL LIBENT
  84. LT_Init(VOID)
  85. {
  86.     BOOL success = TRUE;
  87.  
  88.     #ifndef LINK_LIB
  89.     {
  90.         extern struct Library __far * AbsExecBase;
  91.  
  92.         SysBase = AbsExecBase;
  93.     }
  94.     #endif    // LINK_LIB
  95.  
  96.     if(SysBase == NULL || SysBase->lib_Version < 37)
  97.     {
  98.         success = FALSE;
  99.     }
  100.     else
  101.     {
  102.         STATIC struct LibraryInitEntry InitTable[] =
  103.         {
  104.             TRUE,    "intuition.library",    &IntuitionBase,
  105.             TRUE,    "graphics.library",        &GfxBase,
  106.             TRUE,    "utility.library",        &UtilityBase,
  107.             TRUE,    "gadtools.library",        &GadToolsBase,
  108.             TRUE,    "keymap.library",        &KeymapBase,
  109.             TRUE,    "layers.library",        &LayersBase,
  110.             FALSE,    "locale.library",        (struct Library **)&LocaleBase
  111.         };
  112.  
  113.         STATIC struct ClassInitEntry ClassInitTable[] =
  114.         {
  115.             IMAGECLASS,    
  116.             sizeof(ImageInfo),
  117.             (HOOKFUNC)LTP_ImageDispatch,
  118.             <P_ImageClass,
  119.  
  120.             #ifdef DO_LEVEL_KIND
  121.             {
  122.                 GADGETCLASS,
  123.                 sizeof(struct SliderClassData),
  124.                 (HOOKFUNC)LTP_LevelClassDispatcher,
  125.                 <P_LevelClass,
  126.             },
  127.             #endif    /* DO_LEVEL_KIND */
  128.  
  129.             #ifdef DO_POPUP_KIND
  130.             {
  131.                 GADGETCLASS,
  132.                 sizeof(PopInfo),
  133.                 (HOOKFUNC)LTP_PopupClassDispatcher,
  134.                 <P_PopupClass,
  135.             },
  136.             #endif    /* DO_POPUP_KIND */
  137.  
  138.             #ifdef DO_TAB_KIND
  139.             {
  140.                 GADGETCLASS,
  141.                 sizeof(TabInfo),
  142.                 (HOOKFUNC)LTP_TabClassDispatcher,
  143.                 <P_TabClass,
  144.             },
  145.             #endif    /* DO_TAB_KIND */
  146.  
  147.             #ifdef DO_TEXTEDIT_KIND
  148.             {
  149.                 GADGETCLASS,
  150.                 sizeof(TextEditInfo),
  151.                 (HOOKFUNC)LTP_TextEditClassDispatcher,
  152.                 <P_TextEditClass,
  153.             },
  154.             #endif    /* DO_TEXTEDIT_KIND */
  155.         };
  156.  
  157.         LONG i;
  158.  
  159.         V39 = (BOOLEAN)(SysBase->lib_Version >= 39);
  160.         V40 = (BOOLEAN)(SysBase->lib_Version >= 40);
  161.  
  162.         InitSemaphore(<P_LockSemaphore);
  163.         NewList((struct List *)<P_LockList);
  164.  
  165.         NewList((struct List *)<P_EmptyList);
  166.  
  167.         #ifdef DO_PICKSHORTCUTS
  168.         {
  169.             InitSemaphore(<P_KeySemaphore);
  170.     
  171.             if(!(LTP_Keys[0] = (UBYTE *)AllocMem(512,MEMF_ANY|MEMF_CLEAR)))
  172.             {
  173.                 success = FALSE;
  174.             }
  175.         }
  176.         #endif    /* DO_PICKSHORTCUTS */
  177.  
  178.         for(i = 0 ; i < NUMELEMENTS(InitTable) ; i++)
  179.         {
  180.             (*InitTable[i].Library) = OpenLibrary(InitTable[i].Name,37);
  181.             if((*InitTable[i].Library) == NULL && InitTable[i].MustOpen)
  182.             {
  183.                 success = FALSE;
  184.             }
  185.         }
  186.  
  187.         if(success)
  188.         {
  189.             LTP_NumberFormat = "%ld";
  190.             LTP_DecimalPoint = ".";
  191.  
  192.             if(LocaleBase != NULL)
  193.             {
  194.                 /* Guaranteed to open. */
  195.                 DefaultLocale = OpenLocale(NULL);
  196.  
  197.                 LTP_DecimalPoint = DefaultLocale->loc_DecimalPoint;
  198.  
  199.                 if(LocaleBase->lb_SysPatches)
  200.                     LTP_NumberFormat = "%lD";
  201.             }
  202.  
  203.             for(i = 0 ; i < NUMELEMENTS(ClassInitTable) ; i++)
  204.             {
  205.                 (*ClassInitTable[i].ClassPtr) = MakeClass(NULL,ClassInitTable[i].ClassName,NULL,ClassInitTable[i].InstanceSize,0);
  206.                 if((*ClassInitTable[i].ClassPtr) != NULL)
  207.                 {
  208.                     (*ClassInitTable[i].ClassPtr)->cl_Dispatcher.h_Entry = ClassInitTable[i].Dispatcher;
  209.                 }
  210.                 else
  211.                 {
  212.                     success = FALSE;
  213.                     break;
  214.                 }
  215.             }
  216.         }
  217.     }
  218.  
  219.     if(NO success)
  220.     {
  221.         LT_Exit();
  222.     }
  223.  
  224.     return(success);
  225. }
  226.  
  227.  
  228. /*****************************************************************************/
  229.  
  230.  
  231. /****** gtlayout.library/LT_Exit ******************************************
  232. *
  233. *   NAME
  234. *    LT_Exit -- Clean up user interface allocations
  235. *
  236. *   SYNOPSIS
  237. *    LT_Exit();
  238. *
  239. *    VOID LT_Exit(VOID);
  240. *
  241. *   FUNCTION
  242. *    When you are finished with user interface creation and
  243. *    do not not need the code any more you should call this
  244. *    routine. It will free all the memory allocated by
  245. *    LT_Init(), close libraries, etc.
  246. *
  247. *   INPUTS
  248. *    none
  249. *
  250. *   RESULT
  251. *    none
  252. *
  253. *   NOTES
  254. *    This function is not present in the shared library, only
  255. *    in the link library. You need not and cannot invoke it in
  256. *    the shared library.
  257. *
  258. *   SEE ALSO
  259. *    gtlayout.library/LT_Init
  260. *
  261. ******************************************************************************
  262. *
  263. */
  264.  
  265. VOID LIBENT
  266. LT_Exit(VOID)
  267. {
  268.     if(SysBase != NULL && SysBase->lib_Version >= 37)
  269.     {
  270.         #ifdef DO_PICKSHORTCUTS
  271.         {
  272.             FreeMem(LTP_Keys[0],512);
  273.             LTP_Keys[0] = LTP_Keys[1] = NULL;
  274.         }
  275.         #endif
  276.  
  277.         #ifdef DO_LEVEL_KIND
  278.         {
  279.             if(LTP_LevelClass)
  280.             {
  281.                 FreeClass(LTP_LevelClass);
  282.                 LTP_LevelClass = NULL;
  283.             }
  284.         }
  285.         #endif    /* DO_LEVEL_KIND */
  286.  
  287.         #ifdef DO_POPUP_KIND
  288.         {
  289.             if(LTP_PopupClass)
  290.             {
  291.                 FreeClass(LTP_PopupClass);
  292.                 LTP_PopupClass = NULL;
  293.             }
  294.         }
  295.         #endif    // DO_POPUP_KIND
  296.  
  297.         #ifdef DO_TAB_KIND
  298.         {
  299.             if(LTP_TabClass)
  300.             {
  301.                 FreeClass(LTP_TabClass);
  302.                 LTP_TabClass = NULL;
  303.             }
  304.         }
  305.         #endif    // DO_TAB_KIND
  306.  
  307.         #ifdef DO_TEXTEDIT_KIND
  308.         {
  309.             if(LTP_TextEditClass)
  310.             {
  311.                 FreeClass(LTP_TextEditClass);
  312.                 LTP_TextEditClass = NULL;
  313.             }
  314.         }
  315.         #endif    // DO_TEXTEDIT_KIND
  316.  
  317.         if(LTP_ImageClass)
  318.         {
  319.             FreeClass(LTP_ImageClass);
  320.             LTP_ImageClass = NULL;
  321.         }
  322.  
  323.         if(DefaultLocale)
  324.         {
  325.             CloseLocale(DefaultLocale);
  326.             DefaultLocale = NULL;
  327.         }
  328.  
  329.         CloseLibrary(LocaleBase);
  330.         LocaleBase = NULL;
  331.  
  332.         CloseLibrary(KeymapBase);
  333.         KeymapBase = NULL;
  334.  
  335.         CloseLibrary(GadToolsBase);
  336.         GadToolsBase = NULL;
  337.  
  338.         CloseLibrary(UtilityBase);
  339.         UtilityBase = NULL;
  340.  
  341.         CloseLibrary(GfxBase);
  342.         GfxBase = NULL;
  343.  
  344.         CloseLibrary(IntuitionBase);
  345.         IntuitionBase = NULL;
  346.     }
  347. }
  348.